package cn.qinhao.pethome.system.service.impl;

import cn.qinhao.pethome.basic.base.service.impl.BaseServiceImpl;
import cn.qinhao.pethome.system.domain.Role;
import cn.qinhao.pethome.system.mapper.RoleMapper;
import cn.qinhao.pethome.system.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author qinhao
 * @since 2023-03-04
 */
@Service
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService {
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public void add(Role role) {
        super.add(role);
        //添加另外两张表
        roleMapper.batchAddRoleMenu(role);
        roleMapper.batchAddRolePermission(role);
    }

    @Override
    public void delete(Long id) {
        super.delete(id);
        //删除另外两张表
        roleMapper.delRoleMenu(id);
        roleMapper.delRolePermission(id);
    }

    @Override
    public void update(Role role) {
        super.update(role);
        //先删除自己，再添加，达到修改
        roleMapper.delRoleMenu(role.getId());
        roleMapper.delRolePermission(role.getId());
        roleMapper.batchAddRoleMenu(role);
        roleMapper.batchAddRolePermission(role);
    }

}
